package com.ygo.feihua;

import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;
import android.widget.TextView;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;
import com.ygo.feihua.BmobTable.MyUser;
import com.ygo.feihua.BmobTable.Zhuti;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.ygo.feihua.Management.*;
import com.ygo.feihua.util.*;

public class ZhutiShenhe extends AppCompatActivity
{
	ListView sh_list;
	String sh="审核成功";
	List<Map<String,Object>> data=new ArrayList<Map<String,Object>>();;
	TextView sh_nos;
	shitem si;
	private Gongju gj;
	private DialogUtils du;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO: Implement this method
		super.onCreate(savedInstanceState);
		setContentView(R.layout.zhuti_shenhe);
		gj=Gongju.getdx(this);
		du=DialogUtils.getdx(this);
		du.dialogj1(false,"","加载中");
		
		sh_list=(ListView) findViewById(R.id.sh_list);
		sh_nos=(TextView) findViewById(R.id.sh_nos);
		
		
		gj.cshToolbar((Toolbar) findViewById(R.id.toolbar),"我的上传");
		
	sh_nos.setVisibility(View.GONE);
		UserManagement um=UserManagement.getDx();
		if(um.getUser()!=null){	
			BmobQuery<Zhuti> zt=new BmobQuery<Zhuti>();
			zt.addWhereEqualTo("ztuser",um.getUser());
			zt.order("-updatedAt");
			zt.findObjects( new FindListener<Zhuti>(){

					@Override
					public void done(List<Zhuti> p1, BmobException p2)
					{
						if(p2==null){
							du.dis();
							if(p1.size()==0){

								sh_nos.setVisibility(View.VISIBLE);
								sh_list.setVisibility(View.GONE);
							}else{
								sh_nos.setVisibility(View.GONE);
								for(Zhuti ztt:p1){

									Map<String,Object> map=new 	HashMap<String,Object>();
									map.put("tb", ztt.getzttb().getFileUrl());
									map.put("name",ztt.getztname());
									map.put("jie",ztt.getztjie());
									int s=ztt.getZtsh();
									switch(s){
										case 1:
											sh="审核成功";
											break;
										case 2:
											sh="审核中";
											break;
										case 3:
											sh="审核失败\n失败原因:"+ztt.getztyy();
											break;


									}

									map.put("sh",sh);
									data.add(map);

								}
								si=new shitem(ZhutiShenhe.this,data);
								sh_list.setAdapter(si);
							}
							
							
						}else{
							
							du.dis();
							sh_nos.setVisibility(View.VISIBLE);
							sh_list.setVisibility(View.GONE);
							sh_nos.setText("查询失败");
							gj.show("查询失败"+p2);
							
						}
						// TODO: Implement this method
					}
				});	
				
		}else{
		
		}
	}
}
